package com.example.rfidserver.home;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.rfidserver.R;
import com.example.rfidserver.consume.ConsumeManagerActivity;
import com.example.rfidserver.server.ServerHelper;
import com.example.rfidserver.ticket.TicketManagerActivity;
import com.example.rfidserver.utils.DbHelper;

public class HomeActivity extends AppCompatActivity {
    private final static String DB_PATH = "/data/data/com.example.rfidserver/files/a.db";
    private final static int DB_VERSION = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        //初始化数据库
        DbHelper dbHelper = new DbHelper(this,DB_PATH,null,DB_VERSION);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.close();
        /*
         * My Server @_@~@_@
         * */
        //开启服务器线程
        startServer();

    }




    //点击相应按钮，可以传递不同的viewid
    // 可以跳转到不同界面
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ticketManager:     //门票管理
                Intent ticketManagerIntent = new Intent(this, TicketManagerActivity.class);
                startActivity(ticketManagerIntent);
                break;
            case R.id.consumeManager:   //积分管理
                Intent consumeManagerIntent = new Intent(this, ConsumeManagerActivity.class);
                startActivity(consumeManagerIntent);
                break;
        }
    }


    //开启服务器进行监听
    public void startServer(){
        ServerHelper serverHelper = new ServerHelper();
        try {
            serverHelper.startServer();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}